<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>

    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
    <script src="../../static/js/live2d.min.js" th:src="@{/js/live2d.min.js}"></script>

    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
</head>
<body>

<br>
<br>
<br>

<!--<div class="ui container m-padded-tb-massive" style="max-width: 30em !important;" >-->
<!--    <div class="ui container">-->
<!--        <div class="column">-->
<!--            <h2 class="ui teal image header">-->
<!--&lt;!&ndash;                https://unsplash.it/800/450?image=1079&ndash;&gt;-->
<!--                <img src="../../static/images/logo.png" th:src="@{/images/logo.png}" class="image">-->
<!--                <div class="ui content" style="text-align: center !important;">-->
<!--                    管理后台登录-->
<!--                </div>-->
<!--            </h2>-->
<!--            <form class="ui large form " method="post" th:action="@{/admin/login}">-->
<!--                <div class="ui stacked segment">-->
<!--                    <div class="field">-->
<!--                        <div class="ui left icon input">-->
<!--                            <i class="user icon"></i>-->
<!--                            <input type="text" name="username" placeholder="用户名">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="field">-->
<!--                        <div class="ui left icon input">-->
<!--                            <i class="lock icon"></i>-->
<!--                            <input type="password" name="password" placeholder="密码">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <button class="ui fluid large teal submit button">登  录</button>-->
<!--                </div>-->

<!--                <div class="ui error message"></div>-->

<!--            </form>-->

<!--        </div>-->
<!--    </div>-->
<!--</div>-->



<form class="form-signin" th:action="@{/admin/login}" method="post">
    <div id="stage">
        <div id="inner">
            <div id="cover">
                <div id="text">
                    <span style="color: cyan;">MIMI</span><span style="color: white;">POWERED</span>
                </div>
                <div id="detail"></div>
                <div id="handle"></div>
            </div>
            <canvas class="mb-4" id="live2d" width="800" height="800"></canvas>
        </div>
        <a id="info" href="javascript:info()"><i class="fa fa-lg fa-info"></i></a>
        <a id="refresh" href="javascript:refresh()"><i class="fa fa-lg fa-refresh"></i></a>
    </div>

    <h2 class="ui teal center aligned header content" style="text-align: center !important;">
        管理后台登录
    </h2>

    <label for="room" class="sr-only">用户名</label>
    <input type="text" name="username" class="form-control" placeholder="用户名" required autofocus>
    <label for="pass" class="sr-only">密码</label>
    <input type="password" name="password" class="form-control" placeholder="密码" required>
    <div class="checkbox mb-3">
        <label class="ui inverted" style="color: whitesmoke">
            <input type="checkbox" value="remember-me"> 记住我
        </label>
    </div>
    <button class="ui fluid large teal submit button" type="submit">登录</button>
    <div class="ui mini message red" th:unless="${#strings.isEmpty(message)}" th:text="${message}">用户名或密码错误</div>
</form>

<script>
    window.addEventListener("load", () => {
        "use strict";

        if (!CSS.supports("clip-path", "circle(120px at center)")) {
            document.getElementById("stage").innerHTML = '<img src="../../static/images/screenshot-1.png" th:src="@{/images/screenshot-1.png}" alt="">';
            return;
        }

        let apiPath = "https://live2d.fghrsh.net/api", state = 0,
            modelId = localStorage.getItem("modelId"),
            modelTexturesId = localStorage.getItem("modelTexturesId");
        if (modelId === null) {
            modelId = 1;
            modelTexturesId = 53;
        }
        loadModel(modelId, modelTexturesId);

        function loadModel(modelId, modelTexturesId) {
            localStorage.setItem("modelId", modelId);
            if (modelTexturesId === undefined) modelTexturesId = 0;
            localStorage.setItem("modelTexturesId", modelTexturesId);
            loadlive2d("live2d", `${apiPath}/get/?id=${modelId}-${modelTexturesId}`, null);
            console.log("live2d", `模型 ${modelId}-${modelTexturesId} 加载完成`);
            setTimeout(() => {
                coverPosition("80%");
                state = 2;
            }, 2000);
        }

        function loadRandModel() {
            const modelId = localStorage.getItem("modelId"),
                modelTexturesId = localStorage.getItem("modelTexturesId");
            fetch(`${apiPath}/rand_textures/?id=${modelId}-${modelTexturesId}`)
                .then(response => response.json())
                .then(result => {
                    loadModel(modelId, result.textures.id);
                    setTimeout(() => {
                        state = 2;
                        coverPosition("80%");
                        document.getElementById("refresh").setAttribute("href", "javascript:refresh()");
                    }, 1000);
                });
        }

        function loadOtherModel() {
            const modelId = localStorage.getItem("modelId");
            fetch(`${apiPath}/switch/?id=${modelId}`)
                .then(response => response.json())
                .then(result => {
                    loadModel(result.model.id);
                });
        }

        function coverPosition(pos) {
            document.getElementById("cover").style.bottom = pos;
        }

        window.info = function() {
            fetch("https://v1.hitokoto.cn")
                .then(response => response.json())
                .then(result => {
                    alert("「" + result.hitokoto + "」——" + result.from);
                });
        };

        window.refresh = function() {
            state = 0;
            coverPosition("10%");
            document.getElementById("refresh").setAttribute("href", "javascript:void(0)");
            setTimeout(loadRandModel, 1000);
        };

        document.getElementById("handle").addEventListener("click", () => {
            if (state === 1) {
                state = 2;
                coverPosition("80%");
            }
            else if (state === 2) {
                state = 1;
                coverPosition("20%");
            }
        });

        document.querySelector("input[type=password]").addEventListener("focus", () => {
            if (state === 2) {
                state = 1;
                coverPosition("20%");
            }
        });
        document.querySelector("input[type=password]").addEventListener("blur", () => {
            if (state === 1) {
                state = 2;
                coverPosition("80%");
            }
        });
    });
</script>
</body>


<style>
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .checkbox {
font-weight: 400;
}
.form-signin .form-control {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type=text] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type=password] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
#stage {
position: relative;
}
#stage img {
width: 100%;
margin-bottom: 20px;
border-radius: 20px;
}
#stage a {
position: absolute;
width: 2em;
height: 2em;
border-radius: 50%;
}
#inner {
position: relative;
background-color: #999;
clip-path: circle(120px at center);
}
#cover {
position: absolute;
background-color: #CB3837;
width: 100%;
height: 100%;
bottom: 10%;
transition: all 1s;
box-shadow: 0 0 0 5px rgba(0, 0, 0, .1);
}
#text {
position: absolute;
bottom: 30%;
font-size: 2em;
left: 50%;
transform: translateX(-50%);
opacity: 0.4;
font-weight: bold;
}
#detail {
position: absolute;
background: rgba(255, 255, 255, .1);
width: 100%;
height: 10px;
bottom: 0;
}
#handle {
position: absolute;
background: #ccc;
bottom: -2px;
box-shadow: 0 1px 0 1px rgba(0, 0, 0, .1);
height: 8px;
left: 50%;
margin-left: -15px;
width: 30px;
cursor: pointer;
}
#info {
left: 40px;
bottom: 20px;
}
#refresh {
right: 40px;
bottom: 20px;
}
#live2d {
cursor: grab;
height: 300px;
width: 300px;
}
#live2d:active {
cursor: grabbing;
}
</style>


</html>